import {
    createRouter,
    createWebHistory
} from 'vue-router'
import UserManagement from '../views/UserManagement.vue'
import Login from '../views/login.vue'
import DriverManagement from '../views/DriverManagement.vue'
import OrderManagement from '../views/OrderManagement.vue'

const routes = [

    {
        path: '/usermanagement',
        name: 'usermanagement',
        component: UserManagement,
        meta: {
            title: '用户管理',
            icon: 'user'
        }
    }, {
        path: '/drivermanagement',
        name: 'drivermanagement',
        component: DriverManagement,
        meta: {
            title: '司机管理',
            icon: 'user'
        }
    },{
        path: '/ordermanagement',
        name: 'ordermanagement',
        component: OrderManagement,
        meta: {
            title: '司机管理',
            icon: 'user'
        }
    },
    {
        path: '/',
        name: 'login',
        component: Login,
        meta: {
            title: '登录',
            icon: 'user'
        }
    }
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

router.beforeEach((to, from, next) => { //路由守卫（判定是否登录）
	if (to.fullPath != "/") {
		if (localStorage.getItem("username") == null || localStorage.getItem("token") == null) {
			next("/")
		} else {
			next()
		}
	} else {
		next()
	}
})
export default router
